package next.fire.spinus.logx.provider.huawei.conf;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * Created by daibing on 2023/4/13.
 */
public class HuaweiLogConfigHolder {
    private static final HuaweiLogConfigHolder INSTANCE = new HuaweiLogConfigHolder();
    private final ConcurrentMap<String, HuaweiLogConfig> configMap = new ConcurrentHashMap<>(1);

    public static HuaweiLogConfigHolder get() {
        return INSTANCE;
    }

    public HuaweiLogConfig select(String logStoreCode) {
        return configMap.get(logStoreCode);
    }

    public void reload(List<HuaweiLogConfig> huaweiLogConfigs) {
        synchronized (configMap) {
            configMap.clear();
            for (HuaweiLogConfig huaweiLogConfig : huaweiLogConfigs) {
                configMap.put(huaweiLogConfig.getLogStoreCode(), huaweiLogConfig);
            }
        }
    }
}
